import InitWebChrome.Init;


import org.junit.jupiter.api.Assertions;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import sun.plugin.javascript.navig.Document;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class Test {

private static Logger loggerFactory = LoggerFactory.getLogger(Test.class);

    public static void main(String[] args) throws InterruptedException {
test01();
    }

    public static void test01() throws InterruptedException {
       WebDriver webDriver =  Init.getWebDriver();
       webDriver.get("http://127.0.0.1:58080/sign-in.html");

       webDriver.findElement(By.cssSelector("#username")).sendKeys("test001");
       webDriver.findElement(By.id("password")).sendKeys("123");
       webDriver.findElement(By.id("submit")).click();

     /*   WebDriverWait webDriverWait = (WebDriverWait) new WebDriverWait(webDriver,3)
                .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#article_list_board_title")));
        webDriverWait.wait();*/

        Thread.sleep(1000);
    String currentUrl = webDriver.getCurrentUrl();
        if(currentUrl.equals("http://127.0.0.1:58080/index.html")){
            System.out.println("登录测试通过");
        }

      webDriver.findElement(By.xpath("//*[@id=\"bit-forum-content\"]/div[1]/div/div/div[2]/div/a[1]")).click();

        Thread.sleep(1000);

        //这个标题可以写入
webDriver.findElement(By.xpath("//*[@id=\"article_post_title\"]")).sendKeys("selenium自动化测试");
        System.out.println("111111");

 Thread.sleep(3000);

 //此时是进行内容的编写



      webDriver.findElement(By.xpath("//*[@id=\"nav_board_index\"]/a/span[2]")).click();
      Thread.sleep(3000);
      String currentUrl1 = webDriver.getCurrentUrl();
      if(currentUrl1.equals("http://127.0.0.1:58080/index.html")){
          System.out.println("通过");
      }
      webDriver.findElement(By.xpath("//*[@id=\"index_nav_avatar\"]")).click();
      webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
      webDriver.findElement(By.xpath("//*[@id=\"index_user_profile\"]")).click();
     String Text =  webDriver.findElement(By.xpath("//*[@id=\"profile_nickname\"]")).getText();
      if(Text.equals("测试用户1")){
          System.out.println("用户测试通过通过");
      }
    webDriver.findElement(By.xpath("//*[@id=\"nav_board_index\"]/a/span[2]")).click();
      Thread.sleep(3000);
      webDriver.findElement(By.xpath("//*[@id=\"artical-items-body\"]/div[1]/div/div[2]/div[1]/a/strong")).click();
     String Count = webDriver.findElement(By.xpath("//*[@id=\"details_article_likeCount\"]")).getText();
     Integer likeCount = Integer.valueOf(Count);
     if(likeCount==0){
         System.out.println("点赞测试通过");
     }

   webDriver.manage().window().fullscreen();

     webDriver.findElement(By.xpath("//*[@id=\"topBoardList\"]/li[3]/a/span[2]")).click();
   String articleCount =  webDriver.findElement(By.xpath("//*[@id=\"article_list_count_board\"]")).getText();
        System.out.println(articleCount);
        webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
   if(articleCount.equals("帖子数量: 15")){
       System.out.println("帖子个数正确");
   }

webDriver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg")).click();
        List<WebElement> list = webDriver.findElements(By.name("status-dot d-block"));
                int count = list.size();
        System.out.println(count);
   if(count==5){
       System.out.println("个数是一样的");
   }
Thread.sleep(1000);
   webDriver.findElement(By.xpath("//*[@id=\"index_message_offcanvasEnd\"]/div[1]/button")).click();
   webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
   webDriver.findElement(By.xpath("//*[@id=\"nav_board_index\"]/a/span[2]")).click();
   webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
   webDriver.findElement(By.xpath("//*[@id=\"artical-items-body\"]/div[1]/div/div[2]/div[1]/a/strong")).click();
   WebDriverWait webDriverWait = new WebDriverWait(webDriver,3);
   webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"bit-forum-content\"]/div[2]/div/div/div[1]/div[2]/div[2]/div/div[3]/div/a/span")));
webDriver.findElement(By.xpath("//*[@id=\"index_nav_avatar\"]")).click();
Thread.sleep(1000);
webDriver.findElement(By.xpath("//*[@id=\"index_user_settings\"]")).click();
 Thread.sleep(1000);
 webDriver.findElement(By.xpath("//*[@id=\"settings_input_oldPassword\"]")).sendKeys("123");
 webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
 webDriver.findElement(By.xpath("//*[@id=\"settings_input_newPassword\"]")).sendKeys("456");
 webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
 webDriver.findElement(By.xpath("//*[@id=\"settings_input_passwordRepeat\"]")).sendKeys("456");
 webDriver.manage().timeouts().implicitlyWait(3,TimeUnit.SECONDS);
 webDriver.findElement(By.cssSelector("#settings_submit_password")).submit();




    }
}
